import dashscope
from http import HTTPStatus


messages = [
    {'role': 'system', 'content': '你是一个AI助理.'},
    {'role': 'user', 'content': '请介绍一下通义千问'}
]

response = dashscope.Generation.call(
    model=dashscope.Generation.Models.qwen_turbo,
    messages=messages,
    result_format='message',  # 将返回结果格式设置为 message
    api_key='sk-c98c8f9c9e474aea9c4d56bd52fcc001',
)

if response.status_code == HTTPStatus.OK:
    print(response.output.choices[0].message['content'])
